<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href='saler.css' rel="stylesheet" type="text/css"/>	
<link href="../css/default.css" rel="stylesheet" type="text/css"/>	
<link href="facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>

<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.7.1.custom.min.js"></script>
<script src="facebox/facebox.js" type="text/javascript"></script>

		<script type="text/javascript">
			$(function(){			
				$('a[rel*=facebox]').facebox();				
			
			});		
			
		</script>

</head>
<?php 
require_once("..\\common.php");
require_once("..\\predefine.php");
$admin = false; 
CheckSalerLogon();
?>



<body>

<?php
$posts = $_POST; 
//  清除一些空白符号 
foreach ($posts as $key => $value) {
    $posts[$key] = trim($value); 
} 

//
$TypeCondition = "";
if(isset($posts["clienttype"]))
{
	$clienttype = $posts["clienttype"];
	if($clienttype>=0)
	{
		$TypeCondition = sprintf(" AND type = %d",$clienttype);
	}
}
//
$NameCondition ="";
if(isset($posts["clientname"]))
{
	$clientname = $posts["clientname"];
	if($clientname!="")
	{
		$NameCondition = sprintf(" AND name like '%%%s%%' ",$clientname);
	}
}
//
//echo $posts["contact"];
$ContactCondition="";
if(isset($posts["contact"]))
{
	$contact = $posts["contact"];
	if($contact!="")
	{
		$ContactCondition = sprintf(" AND contact like '%%%s%%'", $contact);
	}
}
//echo $ContactCondtion;
//
$minFundCondition="";
if(isset($posts["minfund"]))
{
	$minfund = $posts["minfund"];
	if($minfund!=""){
		$minFundCondition = sprintf(" AND fund>=%f",$minfund);
	}
}
$maxFundCondition="";
if(isset($posts["maxfund"]))
{
	$maxfund = $posts["maxfund"];
	if($maxfund!="")
	{
		$maxFundCondition = sprintf(" AND fund<=%f",$maxfund);
	}
}
//
$demandCondition = "";
if(isset($posts["demand"]))
{
	$demand = $posts["demand"];
	if($demand>=0)
	{
		$demandCondition = sprintf(" AND demand=%d",$demand);
	}
}

$charactCondition = "";
if(isset($posts["charact"]))
{
	$charact = $posts["charact"];
	if($charact >=0)
	{
		$charactCondition = sprintf(" AND charact=%d",$charact);
	}
}

$devspdCondition = "";
if(isset($posts["devspeed"]))
{
	$devspeed = $posts["devspeed"];
	if($devspeed>=0)
	{
		$devspdCondition = sprintf(" AND devspeed=%d",$devspeed);
	}
}

//submit time
$FromTimeCondition ="";
if(isset($posts["fromtime"]))
{
	$fromtime = $posts["fromtime"];
	if($fromtime!="")
	{
		$FromTimeCondition = sprintf(" AND submit_time>='%s'",$fromtime);
	}
}
$ToTimeCondition = "";
if(isset($posts["totime"]) )
{
	$totime = $posts["totime"];
	if($totime!="")
	{
		$ToTimeCondition = sprintf(" AND submit_time<='%s'", $totime);
	}
}	
//next check time
$nextFromTimeCondition ="";
if(isset($posts["next_fromtime"]))
{
	$nextfromtime = $posts["next_fromtime"];
	if($nextfromtime!="")
	{
		$nextFromTimeCondition = sprintf(" AND next_devtime>='%s'",$nextfromtime);
	}
}
$nextToTimeCondition = "";
if(isset($posts["next_totime"]) )
{
	$nexttotime = $posts["next_totime"];
	if($nexttotime!="")
	{
		$nextToTimeCondition = sprintf(" AND next_devtime<='%s'", $nexttotime);
	}
}	

//product
$ProductCondition ="";
if(isset($posts["product"]))
{
	$product = $posts["product"];
	if($product !="")
	{
		$ProductCondition = sprintf(" AND product like '%%%s%%' ",$product);
	}
}
//remark
$RemarkCondition = "";
if(isset($posts["remark"]))
{
	$remark = $posts["remark"];
	if($remark !="")
	{
		$RemarkCondition = sprintf(" AND remark like '%%%s%%'",$remark);
	}
}

$salerid = $_SESSION["salerid"];
$query ="SELECT id,name,submit_time,next_devtime,fund,demand,charact,devspeed,othersalers,deal_time,deal_money, addict_dev, suppose_saler,product,remark,type,contact FROM client WHERE id IN (SELECT clientid FROM client_saler_rel WHERE salerid=$salerid AND state ='active' ) ";

$conditionArray = array($query,$TypeCondition,$NameCondition,$ContactCondition,$minFundCondition,$maxFundCondition,$demandCondition,$FromTimeCondition,$ToTimeCondition,$charactCondition,$devspdCondition,$nextFromTimeCondition,$nextToTimeCondition,
$ProductCondition,$RemarkCondition);
$query = implode("", $conditionArray);
//echo $query;
$DB = DBConnect();
$result  = mysql_query($query, $DB);


echo "<table cellspacing='1' cellpadding='1'>
<tr class='list_head'>
<td>ID</td>  <td>类型</td> <td>修改</td> <td>联系方式</td> <td>姓名</td> <td>提交时间</td> <td>回收剩余天数</td><td>下次拜访时间</td>  <td>资金量(万元)</td> <td>需求</td> <td>性格</td> <td>所需开发速度</td> <td>其他开发人员</td>  <td>成交时间</td>  <td>成交金额(万)</td> <td>是否还有开发潜力</td> <td>建议谁继续开发</td> <td>预计产品</td> <td>备注</td> <td>转给其他人员</td> 
</tr>";

$index = 0;
while( $myrow = mysql_fetch_row($result) )
{
	$clientid = $myrow[0];
	$name = $myrow[1];
	$submit_time = $myrow[2];
	$next_devtime = $myrow[3];
	$fund= $myrow[4];
	$demand = ClientNeedList::getItem($myrow[5]);
	$charact = ClientCharaList::getItem($myrow[6]);
	$devspeed = ClientDevSpdList::getItem($myrow[7]);
	$othersalers = $myrow[8];
	$deal_time = $myrow[9];
	$deal_money = $myrow[10];
	$addictd_dev = ($myrow[11]==0)?"否":"是";
	$suppose_saler = $myrow[12];
	$product = $myrow[13];
	$remark = $myrow[14];
	
	$type = $myrow[15];
	$type = ClientType::getItem($type);
	
	$contact = $myrow[16];
	$current_day = date("Y-m-d");
	$submit_day = explode(" ",$submit_time);
	$submit_day = $submit_day[0];
	
	$leftday = 20- (strtotime($current_day) - strtotime($submit_day))/(3600*24);
	if($leftday<0)$leftday = "已回收";

	$index = $index+1;
	$classtype= $index%2==0?'list_eve':'list_odd';
	printf("<tr class='$classtype'> <td>%d</td>
		   		<td>%s</td>
		   		<td><a href=\"clientform1.php?clientid=%d\"><img src='../edit.png'/></a></td>
				<td>%s</td>				
				<td>%s</td> 
				<td>%s</td>  
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>		
				<td><a href='transferclient.php?clientid=%d' rel='facebox'>T</a></td>
				</tr>\n",
			$index,$type,$clientid,$contact,$name,$submit_time,$leftday,$next_devtime,$fund,$demand,$charact,$devspeed,$othersalers,$deal_time,$deal_money,$addictd_dev,$suppose_saler,$product,$remark,$clientid);
}

echo "</table>";

?>

<a href= 'index.php'>回主页</a> 
<a href= 'searchform.php'>重新搜索</a> 

</body>
</html>